import React, { useEffect } from 'react';
import concurrentRequests from './xhr';
import Algorithm from './Algorithm';
import styles from './index.module.less';

export default function Layout() {
  // 函数柯里化(currying)
  const curryingFun = func => {
    const args = [];
    return function result(...rest) {
      if (!rest.length) {
        return func(...args);
      } else {
        args.push(...rest);
        // console.log('result', args)
        return result;
      }
    };
  };

  useEffect(() => {
    concurrentRequests();
    const add = (...args) => args.reduce((a, b) => a + b);
    const sum = curryingFun(add);
    sum(1, 2)(3); // 未真正求值
    sum(4); // 未真正求值
    // console.log('curryingFun add', sum())
  }, []);

  return (
    <React.Fragment>
      优秀集合：https://www.bilibili.com/read/cv19424440?from=articleDetail 优秀站点：https://juejin.cn/post/6844904046436843527#heading-16
      <hr className={[styles?.hr].join(' ')} />
      <Algorithm />
    </React.Fragment>
  );
}
